package net.mihome.app.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;

import net.mihome.app.R;
import net.mihome.app.ui.view.MihomeBigPaperView;
import net.mihome.app.ui.view.MihomeRssTypeView;
import net.mihome.app.ui.view.MihomeZixunTypeView;
import net.mihome.app.ui.view.MyViewLinster;
import net.mihome.app.widget.LoadingDialog;

public class Main2 extends BaseActivity {
	private RadioButton mihomeButton;
	private RadioButton mifuwuButton;
	//底部按钮
	private View bottomMihomeView;
	private View bottomMifuwuView;
	//顶部标签按钮
	private Button tabButtonZixunView;
	private Button tabButtonRedianxinwenView;
	private Button tabButtonLinliquanView;
	//顶部标签栏
	private View tabZixunView;
	private View tabRedianxinwenView;
	private View tabLinliquanView;
	//标签页内部控件
	private MihomeZixunTypeView zixunListView;
	private MihomeRssTypeView redianxinwenListView2;
	private MihomeBigPaperView linliquanListView;
	private LoadingDialog loadingDialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.loadingDialog=new LoadingDialog(this);
		this.loadingDialog.setContentView(R.layout.loadingdialog);
		setContentView(R.layout.main);
		mihomeButton = (RadioButton) findViewById(R.id.main_footbar_news);
		mifuwuButton = (RadioButton) findViewById(R.id.main_footbar_question);
		bottomMifuwuView=findViewById(R.id.mifuwu);
		bottomMihomeView=findViewById(R.id.mihome);
		//tab标签页容器
		tabZixunView=findViewById(R.id.include_zixun_main);
		tabRedianxinwenView=findViewById(R.id.include_rss_main);
		tabLinliquanView=(View) findViewById(R.id.frame_listview_tweet_lay);
		//初始化页面内控件
		zixunListView=(MihomeZixunTypeView) findViewById(R.id.frame_listview_news);
//		redianxinwenListView2=(MihomeRssTypeView) findViewById(R.id.rss_view);
		linliquanListView=(MihomeBigPaperView) findViewById(R.id.dazibao_view);
		//顶部标签按钮
		tabButtonZixunView=(Button) findViewById(R.id.frame_btn_mihome_zixun);
		tabButtonRedianxinwenView=(Button) findViewById(R.id.frame_btn_mihome_redianxinwen);
		tabButtonLinliquanView=(Button) (View) findViewById(R.id.frame_btn_mihome_linliquan);
		//初始化底部按钮
		mihomeButton.setOnClickListener(buttOnClickListener);
		mifuwuButton.setOnClickListener(buttOnClickListener);
		//初始化资讯页面
		initNewsListView();
		tabButtonLinliquanView.setOnClickListener(topTabOnClickListener);
		tabButtonRedianxinwenView.setOnClickListener(topTabOnClickListener);
		tabButtonZixunView.setOnClickListener(topTabOnClickListener);
	}

	//初始化地步按钮
	View.OnClickListener buttOnClickListener=new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			if(view==mihomeButton){
				bottomMihomeView.setVisibility(View.VISIBLE);
				mihomeButton.setChecked(true);
				bottomMifuwuView.setVisibility(View.GONE);
				mifuwuButton.setChecked(false);
			}else{
				bottomMihomeView.setVisibility(View.GONE);
				mihomeButton.setChecked(false);
				bottomMifuwuView.setVisibility(View.VISIBLE);
				mifuwuButton.setChecked(true);
			}
		}
	};
	View.OnClickListener topTabOnClickListener=new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			switch (view.getId()) {
			case R.id.frame_btn_mihome_zixun:
				tabLinliquanView.setVisibility(View.GONE);
				tabRedianxinwenView.setVisibility(View.GONE);
				tabZixunView.setVisibility(View.VISIBLE);
				zixunListView.initData();
				break;
			case R.id.frame_btn_mihome_redianxinwen:
				tabLinliquanView.setVisibility(View.GONE);
				tabRedianxinwenView.setVisibility(View.VISIBLE);
				tabZixunView.setVisibility(View.GONE);
				redianxinwenListView2.initData();
				break;
			case R.id.frame_btn_mihome_linliquan:
				tabLinliquanView.setVisibility(View.VISIBLE);
				tabRedianxinwenView.setVisibility(View.GONE);
				tabZixunView.setVisibility(View.GONE);
				linliquanListView.initData(null);
				break;
			default:
				break;
			}
		}
	};
	/**
	 * 初始化新闻列表
	 */
	private void initNewsListView() {
		tabZixunView=findViewById(R.id.include_zixun_main);
		zixunListView = (MihomeZixunTypeView) findViewById(R.id.frame_listview_news);
		zixunListView.initData();
	}
	/**
	 * 初始化热点新闻（新闻订阅）列表
	 * */
	public void initRedianxinwenLv(){
//		redianxinwenListView2=(MihomeRssTypeView) findViewById(R.id.rss_view);
//		redianxinwenListView2.initData();
		redianxinwenListView2.setMyViewLinster(new MyViewLinster() {
			
			@Override
			public void onLoadComplete() {
				if(loadingDialog.isShowing()){
					loadingDialog.dismiss();
				}
			}

			@Override
			public void onBeforeLoad() {
				if(!loadingDialog.isShowing()){
					loadingDialog.show();
				}
			}
		});
	}

	/**
	 * 初始化邻里圈
	 */
	private void initTweetListView() {
		linliquanListView = (MihomeBigPaperView) findViewById(R.id.dazibao_view);
		linliquanListView.setMyViewLinster(new MyViewLinster() {
			
			@Override
			public void onLoadComplete() {
				if(loadingDialog.isShowing()){
					loadingDialog.dismiss();
				}
			}

			@Override
			public void onBeforeLoad() {
				if(!loadingDialog.isShowing()){
					loadingDialog.show();
				}
			}
		});
	}

}
